//
//  CATiledLayerViewController.m
//  CoreAnimation
//
//  Created by 张国文 on 16/10/18.
//  Copyright © 2016年 hangzhouyijiyin. All rights reserved.
//

#import "CATiledLayerViewController.h"

@interface CATiledLayerViewController ()<CALayerDelegate>

@property (nonatomic, strong) UIScrollView *scrollView;

@property (nonatomic, strong) CATiledLayer *tileLayer;

@end

@implementation CATiledLayerViewController

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.tileLayer.delegate = nil;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(80, 80, 200, 200)];
    self.scrollView.backgroundColor = [UIColor whiteColor];
    self.scrollView.layer.borderColor = [UIColor cyanColor].CGColor;
    self.scrollView.layer.borderWidth = 1.0f;
    [self.view addSubview:_scrollView];
    
    self.tileLayer = [CATiledLayer layer];
    self.tileLayer.frame = CGRectMake(0, 0, 2048, 2048);
    self.tileLayer.delegate = self;
    [self.scrollView.layer addSublayer:_tileLayer];
    self.scrollView.contentSize = self.tileLayer.frame.size;
    
    [self.tileLayer setNeedsDisplay];
}

- (void)drawLayer:(CATiledLayer *)layer inContext:(CGContextRef)ctx
{
    CGRect bounds = CGContextGetClipBoundingBox(ctx);
    NSLog(@"bounds = %@", [NSValue valueWithCGRect:bounds]);
}


@end
